
<!doctype html>
<html class="no-js">
<#include "../../common/header.ftl">
<script	src="${basePath}/js/goodsType/edit.js?v=201711021700"></script>
<head>
<meta charset="UTF-8">
<title>编辑类型</title>
<style>
	.foot{
		position: absolute;
		left: 10%;
		top: 90%;
	}
	.lable_text{
		padding:0px 8px;
	}
	.hide{
		display:none;
	}
	.readonly-input{
		background-color: #e2e2e2;
	}
	.left{
		float:left;
	    width: 45%;
	}
	.answer-tips{
		color:red;
	}
</style>
</head>
<body>
<div style="min-height: 80%; min-width: 90%; margin: 20px 20px;">
	<div style="width:80%;">
		<form class="layui-form layui-form-pane">
			<div class="layui-form-item">
				<label class="layui-form-label" style="width:112px;">上级分类*</label>
				<div class="layui-input-block">
					<select name="parentId" <#if goodsType.parentId??>disabled</#if> lay-filter="parentId" >
				        <option value="">请选择上级分类</option>
				        <option value="0" data-grade="0" <#if goodsType.parentId?? && goodsType.parentId==0>selected</#if> >一级分类</option>
				         <#list typeList! as type>
				         	<option value="${type.typeId!}" data-grade="1" <#if goodsType.parentId?? && goodsType.parentId == type.typeId>selected</#if>>${type.name}</option>
					        <#list type.childrenList! as secondType>
				         		<option value="${secondType.typeId!}" data-grade="2" <#if goodsType.parentId?? && goodsType.parentId==secondType.typeId>selected</#if>>${type.name}—${secondType.name}</option>
						   		 <#list secondType.childrenList! as thirdType>
				         			<option value="${thirdType.typeId!}" data-grade="3" <#if goodsType.parentId?? && goodsType.parentId==thirdType.typeId>selected</#if>>${type.name}—${secondType.name}—${thirdType.name}</option>
						   		 </#list>
					        </#list>
				         </#list>
				     </select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label" style="width:112px;">类型名称*</label>
				<div class="layui-input-block">
						<input type="text"	name="name" required="" lay-verify="required"
						placeholder="请输入类型名称" value="${goodsType.name!}" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label" style="width:112px;">英文名称*</label>
				<div class="layui-input-block">
						<input type="text"	name="englishName" required="" lay-verify="required"
						placeholder="请输入英文名称" value="${goodsType.englishName!}" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label" style="width:112px;">类型图标*</label>
				<div class="layui-input-block">
					<div class="site-upload">
						<#if goodsType.icon??>
							<img id="imageUrl" data-img="${goodsType.icon}" src="${imgUrl+goodsType.icon}" style="width:120px;height:120px;" >
						<#else>
							<img id="imageUrl" data-img="" src="${basePath}/images/default_goods.jpg" style="width:120px;height:120px;" >
						</#if>
						<div class="site-upbar">
							<div class="layui-box">
								<form target="layui-upload-iframe" method="get" key="set-mine" enctype="multipart/form-data" action="#">
									 <input type="file" name="files" data-type="one" class="layui-upload-file" >
								</form>
							</div>
							<p class="am-form-help">图片尺寸： 宽&nbsp;&nbsp;120PX 高&nbsp;&nbsp;120PX</p>
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
	<div class="foot">
		<button type="button" class="layui-btn layui-btn-normal"
			id="save-button">
			<i class="layui-icon">&#xe605;</i>保存
		</button>
		<button type="button" class="layui-btn layui-btn-normal"
			id="close-button">
			<i class="layui-icon">&#x1006;</i>关闭
		</button>
	</div>
</div>
</body>
<script type="text/javascript">
	var basePath = "${basePath}";
	var imgUrl = "${imgUrl}";
	var init={
	 	typeId:"${goodsType.id!}",
	 	parentId:"${goodsType.parentId!}",
	 	grade:"${goodsType.grade!}",
	 	isUsed:"${goodsType.isUsed!0}"
	}
	layui.use(['form','layer','upload'], function() {
		var form = layui.form();
		var layer = layui.layer;
		layui.upload({
    		url: basePath+'/restful/file/upload.shtml', //上传接口
    		ext: 'jpg|png|bmp|jpeg',
    		method: 'post',
    		success: function(res,input){ //上传成功后的回调
    			console.log(res);
			    if(res.code=="000000"){
				 	var id=res.data[0].id;
				    var src=imgUrl+id;
				    $("#imageUrl").attr("src",src);
				    $("#imageUrl").attr("data-img",id);
			    }else{
			      layer.msg("上传失败")
			    }
			}
  		});
  		form.on("select(parentId)", function(data){
		  	var parentId = data.value;
		  	var optionDom=data.elem[data.elem.selectedIndex];
		  	var grade =$(optionDom).attr("data-grade");
		  	grade++;
		  	init.parentId=parentId;
		  	init.grade=grade;
		});
	});
</script>
</html>
